﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebClient.Controls
{
    public partial class dangnhap : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack) {
                if(Session["users"] == null)
                    this.Login1.Visible = true;
                else
                    this.Login1.Visible = false;
            }
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            String sUserName = this.Login1.UserName;
            String sPassword = this.Login1.Password;
            WebData db = new WebData();
            DTO.Users item = db.login(sUserName, sPassword);
            if (item != null) {
                Session["users"] = item;
                this.Login1.Visible = false;
                if(item.groupID == 4)
                    Response.Redirect("/home.aspx");
                else
                    Response.Redirect("/admin/admin.aspx");
            }
        }
    }
}